public class LoanCalculator {
    private double loanAmount;  // 贷款总额（万元）
    private int loanTerm;       // 贷款时间（月份）
    private double annualInterestRate; // 年利率

    public LoanCalculator(double loanAmount, int loanTerm, double annualInterestRate) {
        this.loanAmount = loanAmount;
        this.loanTerm = loanTerm;
        this.annualInterestRate = annualInterestRate;
    }

    // 计算月利率
    private double getMonthlyInterestRate() {
        return annualInterestRate / 12 / 100; // 转换为小数
    }

    // 计算等额本金还款法的总利息
    public double calculateEqualPrincipalInterest() {
        double monthlyInterestRate = getMonthlyInterestRate();
        double totalInterest = (loanTerm + 1) * loanAmount * monthlyInterestRate / 2;
        return totalInterest;
    }

    // 计算等额本息还款法的总利息
    public double calculateEqualPrincipalAndInterest() {
        double monthlyInterestRate = getMonthlyInterestRate();
        double totalInterest = (loanTerm * loanAmount * monthlyInterestRate * Math.pow(1 + monthlyInterestRate, loanTerm) / (Math.pow(1 + monthlyInterestRate, loanTerm) - 1)) - loanAmount;
        return totalInterest;
    }
}

